{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "\n",
    "with open('id_list_merged.json', 'r') as f:\n",
    "    model_id_list = json.load(f)\n",
    "len(model_id_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from utils import download_readme, dwonload_text_table, parse_markdwon, get_text_table\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下载readme.md文件"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "vscode": {
     "languageId": "raw"
    }
   },
   "source": [
    "for i in range(0, 5000, 100):\n",
    "    print(i, i+50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2024年10月9日 0-50\n",
    "# stard_idx, end_idx = 0, 50\n",
    "stard_idx, end_idx = 100, 150\n",
    "for model_id in tqdm(model_id_list[stard_idx:end_idx]):\n",
    "    download_readme(model_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下载html数据并解析成text和表格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2024年10月9日 0-50\n",
    "# stard_idx, end_idx = 0, 50\n",
    "stard_idx, end_idx = 100, 150\n",
    "for model_id in tqdm(model_id_list[stard_idx:end_idx]):\n",
    "    dwonload_text_table(model_id)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "处理markdown数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "title_content_md = parse_markdwon(\"meta-llama/Llama-3.1-8B-Instruct\")\n",
    "title_content_md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "title_content_html, _ = get_text_table(\"meta-llama/Llama-3.1-8B-Instruct\")\n",
    "title_content_html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "title_content_md.keys(), title_content_html.keys()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "处理得到url链接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from utils import get_url\n",
    "import pandas as pd\n",
    "# model_id = \"meta-llama/Llama-3.1-8B-Instruct\"\n",
    "# stard_idx, end_idx = 0, 50\n",
    "stard_idx, end_idx = 100, 150\n",
    "for model_id in tqdm(model_id_list[stard_idx:end_idx]):\n",
    "    url_content = get_url(model_id)\n",
    "    url_content_path = f'./data/{model_id}/url_content.xlsx'\n",
    "    url_content_pd = pd.DataFrame(url_content, columns=['url', 'raw_paragraph'])\n",
    "    url_content_pd.to_excel(url_content_path)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lccc",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
